using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
using TCDbService;
using TCEntity;

namespace TimeCameraServer.Controllers
{
  [Route("[controller]")]
  public class ShareController : FailureController
  {
    readonly ShareService _service;
    public ShareController(ShareService service) => _service = service;
    [HttpPost("share")]
    public async Task<IActionResult> ShareAsync((User user, int imageId, int communityId) message) => await FailureProcess(async () =>
     {
       await _service.ShareAsync(message.user, message.imageId, message.communityId);
       return NoContent();
     });
    [HttpGet("view")]
    public async Task<IActionResult> ViewAsync((User user, int communityId) message) => await FailureProcess(async () =>
    {
      var shares = await _service.ViewSharedAsync(message.user, message.communityId);
      return Ok(shares);
    });
    [HttpDelete("cancel")]
    public async Task<IActionResult> CancelAsync((User user, int shareId) message) => await FailureProcess(async () =>
    {
      await _service.CancelShareAsync(message.user, message.shareId);
      return NoContent();
    });
    [HttpPut("update")]
    public async Task<IActionResult> ShareAsync(Image image) => await FailureProcess(async () =>
     {
       await _service.ShareAsync(image);
       return NoContent();
     });

  }
}
